<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="数据状态" prop="dataStatus">
        <el-select v-model="queryParams.dataStatus" placeholder="数据状态" @change="getList" clearable>
          <el-option
            v-for="dict in dict.type.data_status_examine_v2"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"

          />
        </el-select>
      </el-form-item>
      <el-form-item label="项目类别" prop="projectCategory">
        <el-select v-model="queryParams.projectCategory" placeholder="项目类别" @change="getList" clearable>
          <el-option
            v-for="dict in dict.type.project_category"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"

          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="立项日期" prop="startDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.startDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择立项日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item label="物流规划" prop="planId">
        <el-input
          v-model="queryParams.planId"
          placeholder="请输入交通物流规划"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主体单位" prop="buildCompany" v-show="isFoldQuery">
        <el-input
          v-model="queryParams.buildCompany"
          placeholder="请输入主体单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="建设单位" prop="buildCompany" v-show="isFoldQuery">
        <el-input
          v-model="queryParams.buildCompany"
          placeholder="请输入建设单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建人" prop="createBy" v-show="isFoldQuery">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入创建人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" v-show="isFoldQuery">
        <el-date-picker
          v-model="createDateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="修改人" prop="updateBy" v-show="isFoldQuery">
        <el-input
          v-model="queryParams.updateBy"
          placeholder="请输入修改人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改时间" v-show="isFoldQuery">
        <el-date-picker
          v-model="updateDateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>
<!--      <el-form-item label="结项日期" prop="endDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.endDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择结项日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="计划建开始设期" prop="planStartDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.planStartDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择计划建开始设期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="计划完成建设期" prop="planEndDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.planEndDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择计划完成建设期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="总投资" prop="totalInvest">-->
<!--        <el-input-->
<!--          v-model="queryParams.totalInvest"-->
<!--          placeholder="请输入总投资"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="完成投资" prop="completeInvest">-->
<!--        <el-input-->
<!--          v-model="queryParams.completeInvest"-->
<!--          placeholder="请输入完成投资"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                <el-button
          plain
          :icon="isFoldQuery ? 'el-icon-caret-top' : 'el-icon-caret-bottom'"
          size="mini"
          @click="foldQuery"
        >
          {{ isFoldQuery ? '折叠' : '展开' }}
        </el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dataBase:transportProject:add']"
        >新增</el-button>
      </el-col>

<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['dataBase:transportProject:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dataBase:transportProject:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="transportProjectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" v-if="false"/>
      <el-table-column label="项目名称" align="center" prop="projectName" width="180" fixed/>
      <el-table-column label="项目类型" align="center" prop="projectType" width="180" fixed>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.project_type" :value="scope.row.projectType"/>
        </template>
      </el-table-column>
      <el-table-column label="项目类别" align="center" prop="projectCategory" width="180" fixed>
        <template slot-scope="scope">
          <dict-tag v-if="scope.row.projectType === '1'" :options="dict.type.project_category_1" :value="scope.row.projectCategory"/>
          <dict-tag v-else :options="dict.type.project_category_2" :value="scope.row.projectCategory"/>
        </template>
      </el-table-column>
      <el-table-column label="交通物流规划" align="center" prop="planId" width="180" v-show="false">
        <template slot-scope="scope">

        </template>
      </el-table-column>
      <el-table-column label="交通物流规划" align="center" prop="planName" width="180" >
      </el-table-column>
      <el-table-column label="立项日期" align="center" prop="startDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="主体单位" align="center" prop="mainEntity" width="180"/>
      <el-table-column label="建设单位" align="center" prop="buildCompany" width="180"/>

      <el-table-column label="结项日期" align="center" prop="endDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划建开始设期" align="center" prop="planStartDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planStartDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计划完成建设期" align="center" prop="planEndDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planEndDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="总投资" align="center" prop="totalInvest" width="180"/>
      <el-table-column label="完成投资" align="center" prop="completeInvest" width="180"/>
      <el-table-column label="备注" align="center" prop="remark" width="180"/>
      <el-table-column label="创建人" align="center" prop="createBy" width="220"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="220"/>
      <el-table-column label="修改修改人" align="center" prop="updateBy" width="220"/>
      <el-table-column label="修改时间" align="center" prop="updateTime" width="220"/>
      <el-table-column label="建设状态" align="center" prop="buildStatus" width="180" fixed="right">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.build_status" :value="scope.row.buildStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="数据状态" align="center" prop="dataStatus" width="120" fixed="right">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.data_status_examine_v2" :value="scope.row.dataStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="250">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit-outline"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dataBase:transportProject:edit']"
            v-show="scope.row.dataStatus ===0 || scope.row.dataStatus ===2"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document-checked"
            @click="handleUp(scope.row)"
            v-hasPermi="['dataBase:transportProject:edit']"
            v-show="scope.row.dataStatus ===0 || scope.row.dataStatus ===2"
          >提交
          </el-button>

          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-close"-->
          <!--            @click="handleUpdate(scope.row)"-->
          <!--            v-hasPermi="['dataBase:transportProject:edit']"-->
          <!--            v-show="scope.row.dataStatus ===1"-->
          <!--          >撤回</el-button>-->


          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dataBase:transportProject:remove']"
            v-show="scope.row.dataStatus ===0 || scope.row.dataStatus ===4"
          >删除
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="handleReviewCheck(scope.row)"
            v-hasPermi="['dataBase:transportProject:review']"
            v-show="scope.row.dataStatus ===1"
          >审核通过
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-close"
            @click="handleReviewClose(scope.row)"
            v-hasPermi="['dataBase:transportProject:review']"
            v-show="scope.row.dataStatus ===1"
          >审核驳回
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="handleInfo(scope.row)"
            v-hasPermi="['dataBase:transportProject:edit']"
            v-show="!(scope.row.dataStatus === 0 || scope.row.dataStatus === 2)"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listTransportProject, getTransportProject, delTransportProject, addTransportProject, updateTransportProject } from "@/api/dataBase/transportProject";


export default {
  name: "TransportProject",
  dicts: ['data_status_examine_v2','project_type','project_category', 'project_category_1', 'project_category_2', 'build_status'],
  data() {
    return {
      isFoldQuery:false,
      // 日期范围
      createDateRange: [],
      updateDateRange: [],
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 交通物流项目表格数据
      transportProjectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: undefined,
        projectType: undefined,
        projectCategory: undefined,
        planId: undefined,
        startDate: undefined,
        buildCompany: undefined,
        mainEntity: undefined,
        buildStatus: undefined,
        endDate: undefined,
        planStartDate: undefined,
        planEndDate: undefined,
        totalInvest: undefined,
        completeInvest: undefined,
        dataStatus: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "主键id不能为空", trigger: "blur" }
        ],
        projectName: [
          { required: true, message: "项目名称不能为空", trigger: "blur" }
        ],
        projectType: [
          { required: true, message: "项目类型不能为空", trigger: "change" }
        ],
        projectCategory: [
          { required: true, message: "项目类别不能为空", trigger: "blur" }
        ],
        planId: [
          { required: true, message: "交通物流规划不能为空", trigger: "blur" }
        ],
        startDate: [
          { required: true, message: "立项日期不能为空", trigger: "blur" }
        ],
        buildCompany: [
          { required: true, message: "建设单位不能为空", trigger: "blur" }
        ],
        buildStatus: [
          { required: true, message: "建设状态不能为空", trigger: "change" }
        ],
        endDate: [
          { required: true, message: "结项日期不能为空", trigger: "blur" }
        ],
        planStartDate: [
          { required: true, message: "计划建开始设期不能为空", trigger: "blur" }
        ],
        planEndDate: [
          { required: true, message: "计划完成建设期不能为空", trigger: "blur" }
        ],
        totalInvest: [
          { required: true, message: "总投资不能为空", trigger: "blur" }
        ],
        completeInvest: [
          { required: true, message: "完成投资不能为空", trigger: "blur" }
        ],
        remark: [
          { required: true, message: "备注不能为空", trigger: "blur" }
        ],
        dataStatus: [
          { required: true, message: "数据状态不能为空", trigger: "change" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询交通物流项目列表 */
    getList() {
      this.loading = true
      this.queryParams.params = {}
      if (null != this.createDateRange && '' != this.createDateRange) {
        this.queryParams.params['beginCreateTime'] = this.createDateRange[0]
        this.queryParams.params['endCreateTime'] = this.createDateRange[1]
      }
      if (null != this.updateDateRange && '' != this.updateDateRange) {
        this.queryParams.params['beginUpdateTime'] = this.updateDateRange[0]
        this.queryParams.params['endUpdateTime'] = this.updateDateRange[1]
      }
      listTransportProject(this.queryParams).then(response => {
        this.transportProjectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        projectName: undefined,
        projectType: undefined,
        projectCategory: undefined,
        planId: undefined,
        startDate: undefined,
        buildCompany: undefined,
        buildStatus: undefined,
        mainEntity: undefined,
        endDate: undefined,
        planStartDate: undefined,
        planEndDate: undefined,
        totalInvest: undefined,
        completeInvest: undefined,
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        remark: undefined,
        fileList1: "",
        fileList2: "",
        fileList3: "",
        fileList4: "",
        fileList5: "",
        fileList6: "",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      console.log("点击重置按钮")
      this.createDateRange = []
      this.updateDateRange = []
      this.resetForm("queryForm");
      this.handleQuery();
    },
    foldQuery() {
      this.isFoldQuery = !this.isFoldQuery;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加交通物流项目";
    // },
    handleAdd() {
      this.$router.push({
        path: '/dataBase/transportProject/edit'    // 路由地址自己确认一下
      });
    },
    handleInfo(row) {
      const id = row.id || this.ids[0];
      this.$router.push({
        path: '/dataBase/transportProject/edit',
        query: { id:id }
      })
    },
    handleUpdate(row) {
      const id = row.id || this.ids[0];
      this.$router.push({
        path: '/dataBase/transportProject/edit',
        query: { id }
      })
    },
    /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.loading = true;
    //   this.reset();
    //   const id = row.id || this.ids
    //   getTransportProject(id).then(response => {
    //     this.loading = false;
    //     this.form = response.data;
    //     this.open = true;
    //     this.title = "修改交通物流项目";
    //   });
    // },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateTransportProject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addTransportProject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除交通物流项目编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delTransportProject(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('dataBase/transportProject/export', {
        ...this.queryParams
      }, `transportProject_${new Date().getTime()}.xlsx`)
    },
    handleUp(row) {
      this.$modal.confirm('是否确认提交？').then(() => {
        this.loading = true
        row.dataStatus = 1
        return updateTransportProject(row)
      }).then(() => {
        this.loading = false
        this.getList()
        this.$modal.msgSuccess('提交成功')
      }).catch(() => {
        row.dataStatus = 0
      }).finally(() => {
        this.loading = false
      })
    },
    handleReviewCheck(row) {
      this.$modal.confirm('是否确认通过审核？').then(() => {
        this.loading = true
        row.dataStatus = 3
        return updateTransportProject(row)
      }).then(() => {
        this.loading = false
        this.getList()
        this.$modal.msgSuccess('审核通过成功')
      }).catch(() => {
      }).finally(() => {
        this.loading = false
      })
    },
    handleReviewClose(row) {
      this.$modal.confirm('是否确认驳回？').then(() => {
        this.loading = true
        row.dataStatus = 2
        return updateTransportProject(row)
      }).then(() => {
        this.loading = false
        this.getList()
        this.$modal.msgSuccess('驳回成功')
      }).catch(() => {
      }).finally(() => {
        this.loading = false
      })
    },
  }
};
</script>
